package org.creativor.rayson.transport.server;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import org.creativor.rayson.transport.common.ProtocolType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The class <code>PendingConnectionTest</code> contains tests for the class
 * <code>{@link PendingConnection}</code>.
 * <p>
 * Copyright Creativor Studio (c) 2011
 * 
 * @generatedBy CodePro at 11-5-7 上午3:10
 * @author Nick Zhang
 * @version $Revision: 1.0 $
 */
public class PendingConnectionTest {
	/**
	 * Launch the test.
	 * 
	 * @param args
	 *            the command line arguments
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	public static void main(String[] args) {
		new org.junit.runner.JUnitCore().run(PendingConnectionTest.class);
	}

	/**
	 * Perform pre-test initialization.
	 * 
	 * @throws Exception
	 *             if the initialization fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Before
	public void setUp() throws Exception {
		// TODO: add additional set up code here
	}

	/**
	 * Perform post-test clean-up.
	 * 
	 * @throws Exception
	 *             if the clean-up fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@After
	public void tearDown() throws Exception {
		// TODO: add additional tear down code here
	}

	/**
	 * Run the void close() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testClose_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.close();

		// TODO: add additional test code here
	}

	/**
	 * Run the void close() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testClose_2() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.close();

		// TODO: add additional test code here
	}

	/**
	 * Run the void denyToAccept() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testDenyToAccept_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.denyToAccept();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.lang.NullPointerException
		// at
		// org.creativor.rayson.transport.server.PendingConnection.denyToAccept(PendingConnection.java:53)
	}

	/**
	 * Run the long getId() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testGetId_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		long result = fixture.getId();

		// TODO: add additional test code here
		assertEquals(4L, result);
	}

	/**
	 * Run the ProtocolType getProtocol() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testGetProtocol_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		ProtocolType result = fixture.getProtocol();

		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals((byte) 8, result.getType());
		assertEquals("UNKNOWN", result.name());
		assertEquals("UNKNOWN", result.toString());
		assertEquals(3, result.ordinal());
	}

	/**
	 * Run the byte getVersion() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testGetVersion_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		byte result = fixture.getVersion();

		// TODO: add additional test code here
		assertEquals((byte) -1, result);
	}

	/**
	 * Run the PendingConnection(TransportServer,SocketChannel,SelectionKey)
	 * constructor test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testPendingConnection_1() throws Exception {
		TransportServer server = new TransportServer();
		SocketChannel clientChannel = SocketChannel.open();
		SelectionKey selectionKey = null;

		PendingConnection result = new PendingConnection(server, clientChannel,
				selectionKey);

		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals(
				"{id: 0, protocol: UNKNOWN, version: -1, address: Socket[unconnected]}",
				result.toString());
		assertEquals(0L, result.getId());
		assertEquals((byte) -1, result.getVersion());
	}

	/**
	 * Run the int read() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testRead_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		int result = fixture.read();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:122)
		// at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:163)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.read(PendingConnection.java:69)
		assertEquals(0, result);
	}

	/**
	 * Run the int read() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testRead_2() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		int result = fixture.read();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:122)
		// at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:163)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.read(PendingConnection.java:69)
		assertEquals(0, result);
	}

	/**
	 * Run the int read() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testRead_3() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		int result = fixture.read();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:122)
		// at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:163)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.read(PendingConnection.java:69)
		assertEquals(0, result);
	}

	/**
	 * Run the int read() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testRead_4() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		int result = fixture.read();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:122)
		// at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:163)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.read(PendingConnection.java:69)
		assertEquals(0, result);
	}

	/**
	 * Run the int read() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testRead_5() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		int result = fixture.read();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:122)
		// at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:163)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.read(PendingConnection.java:69)
		assertEquals(0, result);
	}

	/**
	 * Run the int read() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testRead_6() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		int result = fixture.read();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:122)
		// at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:163)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.read(PendingConnection.java:69)
		assertEquals(0, result);
	}

	/**
	 * Run the String toString() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testToString_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		String result = fixture.toString();

		// TODO: add additional test code here
		assertEquals(
				"{id: 17, protocol: UNKNOWN, version: -1, address: Socket[unconnected]}",
				result);
	}

	/**
	 * Run the void write() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testWrite_1() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.write();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:137)
		// at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:324)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.write(PendingConnection.java:114)
	}

	/**
	 * Run the void write() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testWrite_2() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.write();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:137)
		// at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:324)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.write(PendingConnection.java:114)
	}

	/**
	 * Run the void write() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testWrite_3() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.write();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:137)
		// at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:324)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.write(PendingConnection.java:114)
	}

	/**
	 * Run the void write() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:10
	 */
	@Test
	public void testWrite_4() throws Exception {
		PendingConnection fixture = new PendingConnection(
				new TransportServer(), SocketChannel.open(),
				(SelectionKey) null);

		fixture.write();

		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.nio.channels.NotYetConnectedException
		// at
		// sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:137)
		// at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:324)
		// at
		// org.creativor.rayson.transport.server.PendingConnection.write(PendingConnection.java:114)
	}
}